//
//  MBProgressHUD+MJ.m
//
//  Created by mj on 13-4-18.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import "MBProgressHUD+JK.h"
#import "UIImage+GIF.h"
#import "LoadingView.h"
static MBProgressHUD*hud=nil;
@implementation MBProgressHUD (JK)
#pragma mark 显示信息
+(MBProgressHUD*)shareToView:(UIView*)view{
    if (view == nil) view = [UIApplication sharedApplication].keyWindow ;
//    if (!hud) {
        // 快速显示一个提示信息
    [MBProgressHUD dissmiss];
    hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
//    hud.animationType=MBProgressHUDAnimationZoom;
//    }else if (hud.removeFromSuperViewOnHide){
    
        
        
        
//    }
    hud.yOffset = -60.0;
    [hud show:YES];
    return hud;
}

+(MBProgressHUD*)showImage:(NSString*)imageName withStr:(NSString*)str toView:(UIView*)view{
    [self shareToView:view];
    hud.detailsLabelText = str;
    hud.detailsLabelFont = [UIFont systemFontOfSize:14];
    if (imageName) {
        UIImage*image= [UIImage imageNamed:imageName];
        
        UIImageView*imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
        imageView.image=image;
        hud.customView=imageView;
    }

    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    // YES代表需要蒙版效果
    hud.dimBackground = YES;
    
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:2];
    
    
    return hud;
}
+(MBProgressHUD*)showGIF:(NSString*)gifName withStr:(NSString*)str toView:(UIView*)view{
[self shareToView:view];
    hud.detailsLabelText = str;
    hud.detailsLabelFont = [UIFont systemFontOfSize:14];
    
    if (gifName) {
         UIImage*image = [UIImage sd_animatedGIFNamed:gifName];
        UIImageView*imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
        imageView.image=image;
        
        hud.customView = imageView;
    }
    
    

    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    // YES代表需要蒙版效果
    hud.dimBackground = YES;
    
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    return hud;
}
+(MBProgressHUD*)showCustomAnimationWithStr:(NSString*)str toView:(UIView*)view{
    [self shareToView:view];
    
    hud.detailsLabelText = str;
    
    hud.detailsLabelFont = [UIFont systemFontOfSize:14];
    LoadingView* customView=[[LoadingView alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    [customView creaAnimation];
    hud.customView=customView;
    hud.customView.centerY-=10;
    
//
    
    
    
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    // YES代表需要蒙版效果
    hud.dimBackground = YES;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    return hud;
}


+(MBProgressHUD*)showLabWithStr:(NSString*)str toView:(UIView*)view{
[self shareToView:view];
    hud.detailsLabelText = str;
    hud.detailsLabelFont = [UIFont systemFontOfSize:14];

//    hud.labelFont = [UIFont systemFontOfSize:13.0];
    hud.mode = MBProgressHUDModeText;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:2];
    return hud;
}
+(MBProgressHUD*)showActivityWithStr:(NSString*)str toView:(UIView*)view{
 [self shareToView:view];
    hud.detailsLabelText = str;
    hud.detailsLabelFont = [UIFont systemFontOfSize:14];

    hud.mode = MBProgressHUDModeIndeterminate;
    // YES代表需要蒙版效果
//    hud.dimBackground = YES;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    return hud;
    
}
+(MBProgressHUD*)showLineWithStr:(NSString*)str progress:(CGFloat)progress toView:(UIView*)view{
[self shareToView:view];
    hud.detailsLabelText = str;
    hud.detailsLabelFont = [UIFont systemFontOfSize:14];

//    hud.labelFont = [UIFont systemFontOfSize:13.0];
    
    hud.mode = MBProgressHUDModeAnnularDeterminate;
    // YES代表需要蒙版效果
    hud.dimBackground = YES;
    [hud showAnimated:YES whileExecutingBlock:^{
        
        hud.progress = progress;
        
    } completionBlock:^{
        [hud removeFromSuperViewOnHide];
    }];
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    return hud;
}
+(MBProgressHUD*)showProgressWithStr:(NSString*)str progress:(CGFloat)progress toView:(UIView*)view{
[self shareToView:view];
    hud.detailsLabelText = str;
    hud.detailsLabelFont = [UIFont systemFontOfSize:14];

//    hud.labelFont = [UIFont systemFontOfSize:13.0];
    
    hud.mode = MBProgressHUDModeDeterminate;
    // YES代表需要蒙版效果
    hud.dimBackground = YES;
    [hud showAnimated:YES whileExecutingBlock:^{

        hud.progress = progress;

    } completionBlock:^{
        [hud removeFromSuperViewOnHide];
    }];
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    return hud;
}
+(MBProgressHUD*)showLeftImage:(NSString* )image rightLab:(NSString*)labText toView:(UIView*)view{
    [self shareToView:view];
    UIView* vi=[[UIView alloc]init];
    UIView* vi1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth*0.4, kScreenWidth*0.4*0.467)];
    UIImageView* imag=[[UIImageView alloc]init];
    [imag setImage:[UIImage imageNamed:image]];
    UILabel* lab=[[UILabel alloc]init];
    lab.text=labText;
    lab.textColor=[UIColor whiteColor];
    lab.backgroundColor=[UIColor clearColor];
    [vi addSubview:imag];
    [vi addSubview:lab];
    [vi1 addSubview:vi];
   /* [imag mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@20);
        make.height.equalTo(@20);
        make.leading.equalTo(vi);
        make.top.equalTo(vi);
        make.bottom.equalTo(vi);
        
    }];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(vi);
        make.top.equalTo(vi);
        make.bottom.equalTo(vi);
        make.leading.equalTo(imag).with.offset(25);
    }];
    [vi mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(vi1);
    }]; */
    vi1.layer.masksToBounds=YES;
    vi1.layer.cornerRadius=6.0;
    vi1.backgroundColor=RGBA(50, 50, 50, 0.9);
    vi.backgroundColor=[UIColor clearColor];
    hud.customView=vi1;
    hud.color=[UIColor clearColor];
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    
   
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:2];
    return hud;
}
+(MBProgressHUD*)showOtherViewWithXibName:(NSString*)xibName obj:(NSInteger)obj toView:(UIView*)view{
    [self shareToView:view];
    UIView*vi=[[NSBundle mainBundle]loadNibNamed:xibName owner:nil options:nil][obj] ;
    vi.frame=CGRectMake(0, 0, kScreenWidth*0.4, kScreenWidth*0.4*0.467);
    hud.customView=vi;
    hud.color=[UIColor clearColor];
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    
    // YES代表需要蒙版效果
    hud.dimBackground = YES;
    
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:2];
    return hud;
}
+(void)dissmissAfterTime:(CGFloat)time{
    [hud hide:YES afterDelay:time];
}

+(void)dissmiss{
    [hud hide:YES];
}


@end
